package com.gyg.controller;


import com.gyg.client.CloudCollectionClient;
import com.gyg.domain.CloudUser;
import com.gyg.enums.SessionEnum;
import com.gyg.returns.RespEntity;
import com.gyg.vo.param.CollectionParam;
import com.gyg.vo.param.UpdateCollectionParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 文件收藏表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-collection")
@Slf4j
@Api(value = "文件收藏", tags = "文件收藏")
public class CloudCollectionController {

    @Resource
    private CloudCollectionClient cloudCollectionClient;

    @PostMapping("/add")
    @ApiOperation(value = "添加收藏")
    public RespEntity cloudAddCollection (CollectionParam collectionParam, HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        collectionParam.setUserId(cloudUser.getId());
        RespEntity respEntity = cloudCollectionClient.addCollection(collectionParam);
        return respEntity;
    }

    @GetMapping("/list")
    @ApiOperation(value = "收藏列表")
    public RespEntity collectionList(HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        RespEntity respEntity = cloudCollectionClient.collectionList(cloudUser.getId());
        return respEntity;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑收藏文件")
    public RespEntity updateCollection(UpdateCollectionParam updateCollectionParam) {
        RespEntity respEntity = cloudCollectionClient.updateCollection(updateCollectionParam);
        return respEntity;
    }

    @DeleteMapping("/cancel")
    @ApiOperation(value = "取消收藏")
    public RespEntity deleteCollection(CollectionParam collectionParam, HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        collectionParam.setUserId(cloudUser.getId());
        RespEntity respEntity = cloudCollectionClient.cancelCollection(collectionParam);
        return respEntity;
    }

}
